package util;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Application Lifecycle Listener implementation class OnlineListener
 *
 */
//������ʵ�ּ�����������
@WebListener
public class OnlineListener implements HttpSessionListener {
	private int num;
    /**
     * Default constructor. 
     */
    public OnlineListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent se)  { 
         // TODO Auto-generated method stub
    	num++;
		ServletContext context = se.getSession().getServletContext();
		context.setAttribute("onlineUserNum", num);
    }

	/**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent se)  { 
         // TODO Auto-generated method stub
    	num--;
		ServletContext context = se.getSession().getServletContext();
		context.setAttribute("onlineUserNum", num);
    }
	
}
